#ifndef __TcpAcceptor_h__
#define __TcpAcceptor_h__

#include <interfaces/SocketAcceptor.h>
#include "TcpSocket.h"

using namespace Greatewall::Interface;

namespace Greatewall
{
    namespace Network
    {
        class TcpAcceptor : public SocketAcceptor, public TcpSocket
        {
        public:
            TcpAcceptor(SocketEventMonitor& monitor)
                : TcpSocket(monitor)
            {}

            bool
            initTcpAcceptor(short port, std::string netif, int backlog = 10);

            virtual void
            handleInbound();

            // Do nonthing about outbound
            virtual bool
            handleOutbound() { return false;}

            // This must be overloaded by the real acceptor who can create the client
            // handler that knows the rule to handle incoming message.
            virtual SystemSocket*
            createClientHandler(SysSockHandler hdl, std::string host, short port) = 0;

        private:
            bool
            initTcpSock(std::string& host, short port, std::string& netif)
            { return false; }

            bool
            initTcpSock(short port, int backlog, std::string& netif)
            { return TcpSocket::initTcpSock(port, backlog, netif); }

            bool
            initTcpSock(SysSockHandler hdl, std::string host, int port)
            { return false; }
        };
    }
}

#endif
